<?php

namespace App\Service\Third;

use App\Model\OcpcBaiduSearch;
use App\Service\BaseService;

class BaiduSearchAdService extends BaseService
{
    //https://.xx.com/callback/baidu_search_ad?
    //?imei_md5={{IMEI_MD5}}&os={{OS}}&ip={{IP}}&ua={{UA}}&ts={{TS}}&pid={{PLAN_ID}}&uid={{UNIT_ID}}&aid={{IDEA_ID}}&oaid={{OAID}}&oaid_md5={{OAID_MD5}}&click_id={{CLICK_ID}}&callback_url={{CALLBACK_URL}}
    public function handle(): int
    {
        $params = $this->request->all();

        log_info('百度搜索广告监测链接===='.json_encode($params));

        if (OcpcBaiduSearch::existsOaid($params['oaid'] ?? '')) {
            return 1;
        }

        if (OcpcBaiduSearch::existImei($params['imei_md5'] ?? '')) {
            return 1;
        }

        if (OcpcBaiduSearch::existOaidMd5($params['oaid_md5'] ?? '')) {
            return 1;
        }

        return OcpcBaiduSearch::addLog($params);
    }
}